Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 10: Controlling Appearance with Materials

../ch10/10fig09.gif
Figure 10.9

Three blinking spheres.

10fig09.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
    children [
    # Blinking balls
        Transform {
            translation -2.0 0.0 0.0
            children Shape {
                appearance Appearance {
                    material DEF Ball1Color Material {
                        diffuseColor 0.4 0.4 0.4
                    }
                }
                geometry DEF ABall Sphere { }
            }
        },
        Shape {
            appearance Appearance {
                material DEF Ball2Color Material {
                    diffuseColor 0.4 0.4 0.4
                }
            }
            geometry USE ABall
        },
        Transform {
            translation  2.0 0.0 0.0
            children Shape {
                appearance Appearance {
                    material DEF Ball3Color Material {
                        diffuseColor 0.4 0.4 0.4
                    }
                }
                geometry USE ABall
            }
        },
    # Animation clocks
        DEF Clock1 TimeSensor {
            cycleInterval 1.0
            loop TRUE
        },
        DEF Clock2 TimeSensor {
            cycleInterval 1.3
            loop TRUE
        },
        DEF Clock3 TimeSensor {
            cycleInterval 0.7
            loop TRUE
        },
    # Animation paths
        DEF Color1Path ColorInterpolator {
            key [ 0.0, 0.5, 0.5, 1.0 ]
            keyValue [
                1.0 1.0 0.0,  1.0 1.0 0.0,
                0.0 1.0 0.0,  0.0 1.0 0.0,
            ]
        },
        DEF Color2Path ColorInterpolator {
            key [ 0.0, 0.5, 0.5, 1.0 ]
            keyValue [
                0.0 1.0 0.0,  0.0 1.0 0.0,
                0.0 0.0 1.0,  0.0 0.0 1.0,
            ]
        },
        DEF Color3Path ColorInterpolator {
            key [ 0.0, 0.5, 0.5, 1.0 ]
            keyValue [
                0.5 0.5 0.5,  0.5 0.5 0.5,
                1.0 1.0 1.0,  1.0 1.0 1.0,
            ]
        }
    ]
}
ROUTE Clock1.fraction_changed  TO Color1Path.set_fraction
ROUTE Clock2.fraction_changed  TO Color2Path.set_fraction
ROUTE Clock3.fraction_changed  TO Color3Path.set_fraction
ROUTE Color1Path.value_changed TO Ball1Color.set_emissiveColor
ROUTE Color2Path.value_changed TO Ball2Color.set_emissiveColor
ROUTE Color3Path.value_changed TO Ball3Color.set_emissiveColor